﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

//using PowerCreator.LMS.Logic.CourseManager;
//using PowerCreator.LMS.Logic.ProjectManager;
//using PowerCreator.LMS.Logic.QuestionManager;
//using PowerCreator.LMS.Logic.PaperManager;
//using PowerCreator.LMS.Logic.Common;
//using PowerCreator.LMS.Model.Entity;
//using PowerCreator.LMS.Logic.Fpager;
//using System.Text;

//using PowerCreator.LMS.Logic.Common;
using System.Text;
using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.ViewQuery;
using PowerCreator.LMS.Common.Script;

public partial class Theme_3_PaperReSearchList : PowerCreator.LMS.Web.Base.WebBasePage
{
   
    //ManagerPaperInfo manager = new ManagerPaperInfo();
    //ManagerPaperQuestion objpaperquestion = new ManagerPaperQuestion();
    //ManagerPaperUserAnswer objpaperuseranswer = new ManagerPaperUserAnswer();
    //ManagerUserPaperHistoryInfo objuserpaperhistoryinfo = new ManagerUserPaperHistoryInfo();
    //ManagerProjectResource objManagerProjectResource = new ManagerProjectResource();

    ManagerPaper objManagerPaper = new ManagerPaper();
    Course objCourse = new Course();
    ManagerQuestion objManagerQuestion = new ManagerQuestion();
    ViewQuery objViewQuery = new ViewQuery();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.ManagerPaper))
        //{
        //    Script.ShowAndHistory("您没有管理试卷的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
            InitPage();
        }
    }
    protected override void InitPage()
    {
        //lab_TitleInfo.Text = GetLanageValueByKey("lab_ManagerPaperInfo_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);

        lab_PaperName.Text = GetLanageValueByKey("lab_AddPaperInfo_PaperName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lab_PaperState.Text = GetLanageValueByKey("lab_ManagerPaperInfo_PaperState", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private string GetSearch()
    {
        StringBuilder str_search = new StringBuilder();
        //str_search.Append(" 1=1 and PaperBuildState=1  ");
        str_search.Append(" 1=1 and  PaperResearch_BuildState=1 and PaperResearch_ShowState=1 ");

        if (txtPaperName.Text.Trim() != "")
        {
            str_search.Append(" and PaperName like '%" + txtPaperName.Text + "%'");
        }


        return str_search.ToString();
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objManagerPaper.CountPaperResearch(search);
        AspNetPager1.PageSize = LMSPageSize;
    }

    private void BinderGV(string search, int pageIndex)
    {
        DataTable dt = new DataTable();
        dt = objManagerPaper.QueryPaperResearch(search, LMSPageSize, pageIndex);
        DataColumn dc = new DataColumn("SelectTypeNew");
        dt.Columns.Add("url");
        dt.Columns.Add(dc);
        dt.Columns.Add("Index");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["url"] = dt.Rows[i]["PaperResearch_ID"].ToString();

            dt.Rows[i]["Index"] = (pageIndex - 1) * 10 + i + 1;
        }
        gvPaperList.DataSource = dt;
        gvPaperList.DataBind();
    }

    protected void gvPaperList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "btn_open")
        {
            string url = string.Empty;


            url = "OpenPaperResearch.aspx?PaperID=" + e.CommandArgument.ToString();


            Script.NewOpenURL(url);
        }
       
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
    protected void gvPaperList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton ibtnPreview = (LinkButton)e.Row.Cells[8].FindControl("ibtnPreview");
            LinkButton btn_Out = (LinkButton)e.Row.Cells[8].FindControl("btn_Out");

            e.Row.Attributes.Add("bgColor", "#F7FAFF");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FAEDB8'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7FAFF'");


            if (e.Row.Cells[5].Text == "0")
            {
                e.Row.Cells[5].Text = "否";
            }
            else
            {
                e.Row.Cells[5].Text = "是";
            }

            if (e.Row.Cells[7].Text == "0")
            {
                e.Row.Cells[7].Text = "未生成";
                ibtnPreview.Enabled = false;
                btn_Out.Enabled = false;
            }
            else
            {
                e.Row.Cells[7].Text = "已生成";
                ibtnPreview.Enabled = true;
                btn_Out.Enabled = true;
            }

        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }

}
